package com.shop.shoporder.wapController;

import com.shop.shoporder.common.MessageConstants;
import com.shop.shoporder.common.Response;
import com.shop.shoporder.common.UserLoginToken;
import com.shop.shoporder.entity.order.SureOrder;
import com.shop.shoporder.service.SureOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
@CrossOrigin(origins = "*",maxAge = 3600)
@RequestMapping("/wap")
public class SureOrderController {
    @Autowired
    SureOrderService sureOrderService;

    @UserLoginToken
    @ResponseBody
    @RequestMapping(value = "/sureOrder",method = RequestMethod.GET)
    //确认订单
    public Response sureOrder(@RequestParam Map<String,String> map, HttpServletRequest request) {
        SureOrder sureOrder=new SureOrder();
        try{
            sureOrder=sureOrderService.getSureOrderList(map,request);
        }catch (Exception e){
            e.printStackTrace();
            return new Response(MessageConstants.MSG_REGISTER_FAILED,null,0,"获取异常！",request);
        }
        if(sureOrder!=null){
            return new Response(MessageConstants.MSG_SUCCESS,sureOrder,1,"获取成功！",request);
        }else{
            return new Response(MessageConstants.MSG_REGISTER_FAILED,null,0,"获取失败！",request);
        }
    }
    //确认订单 切换地址
    @UserLoginToken
    @ResponseBody
    @RequestMapping(value = "/replaceOrderAddress",method = RequestMethod.GET)
    public Response replaceOrderAddress(@RequestParam Map<String,String> map, HttpServletRequest request) {
        SureOrder sureOrder=new SureOrder();
        try{
            sureOrder=sureOrderService.getSureOrderList1(map,request);
        }catch (Exception e){
            e.printStackTrace();
            return new Response(MessageConstants.MSG_REGISTER_FAILED,null,0,"获取异常！",request);
        }
        if(sureOrder!=null){
            return new Response(MessageConstants.MSG_SUCCESS,sureOrder,1,"获取成功！",request);
        }else{
            return new Response(MessageConstants.MSG_REGISTER_FAILED,null,0,"获取失败！",request);
        }
    }

}
